﻿
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components.Web;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using ZFY.UMC.Model.Dto.User;
using ZFY.UMC.Model.Dto.UserClaim;

namespace ZFY.UMC.BlazorWebAssembly.Pages.User.UserManage
{
    public partial class UserManage
    {
        private static IEnumerable<int> PageItemsSource => new int[] { 5, 10, 20 };
       
        bool _loading = false;
        List<GetUserClaimListOutput> _userClamis = new List<GetUserClaimListOutput>();
    
        private Modal ClaimModal { get; set; }
        private Table<GetUserClaimListOutput> ClaimTable { get; set; }
        List<GetUserListOutput> _userList = new List<GetUserListOutput>() { new GetUserListOutput { 
            Claims = new List<Model.Dto.UserClaim.GetUserClaimListOutput>{ new Model.Dto.UserClaim.GetUserClaimListOutput { ClaimType="role",ClaimValue="管理员" } },
            CreationTime = DateTime.Now,
            Email = "798513242@qq.com",
            Id = 1,
            Name = "pengyue",
            NickName = "茫雾",
            PhoneNumber = "123456789"
        } };
        //public string Display { get; set; }

        //private void PageIndexChanged(PaginationEventArgs args)
        //{
        //    //_navigation.NavigateTo($"mock?type={GetType().ToString().Replace($"{Assembly.GetExecutingAssembly().GetName().Name}.", "")}&page={args.Page}&size={args.PageSize}");
        //}
        //private void ClaimPageIndexChanged(PaginationEventArgs args)
        //{
        //    _displayUserClamis = _userClamis.Skip((_claimPageIndex - 1) * _claimPageSize).Take(_pageSize).ToList();
        //}
        private async Task DisplyClaimsAsync(GetUserListOutput user)
        {
            System.Console.WriteLine(user.Id);
            _userClamis = _userList.FirstOrDefault(x => x.Id == 1).Claims.ToList();
            await ClaimTable.QueryAsync();
            await ClaimModal.Show();
            
        }
        //void HandleClaimOk(MouseEventArgs e)
        //{
        //    _visibleClaim = false;
        //}
        //void HandleClaimCancle(MouseEventArgs e)
        //{
        //    _visibleClaim = false;
        //}
        private Task<QueryData<GetUserListOutput>> OnQueryAsync(QueryPageOptions options)
        {

            System.Console.WriteLine(options.PageIndex);
            IEnumerable<GetUserListOutput> items = _userList;

            // 设置记录总数
            var total = items.Count();

            // 内存分页
            items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();

            return Task.FromResult(new QueryData<GetUserListOutput>()
            {
                Items = items,
                TotalCount = total,
                IsSorted = true,
                IsFiltered = true,
                IsSearch = true
            });
        }
        private Task<QueryData<GetUserClaimListOutput>> OnClaimQueryAsync(QueryPageOptions options)
        {
            IEnumerable<GetUserClaimListOutput> items = _userClamis;

            // 设置记录总数
            var total = items.Count();

            // 内存分页
            items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();

            return Task.FromResult(new QueryData<GetUserClaimListOutput>()
            {
                Items = items,
                TotalCount = total,
                IsSorted = true,
                IsFiltered = true,
                IsSearch = true
            });
        }
    }
}
